package com.suyl.candy.tools;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @author suyanlong
 * @version 1.0
 * @createDate 2020/5/17 19:29
 * @description 获取配置信息工具
 */
//@Component
public class PropertiesServer {

    static Map<String, String> maps = new HashMap<>();

    private static PropertiesUtils properties = new PropertiesUtils("application-map.properties");

    // 方式1：让spring管理起来
    //    @PostConstruct
//    public void init() {
//        Iterator<Map.Entry<Object, Object>> map = properties.properties.entrySet().iterator();
//        while (map.hasNext()) {
//            Map.Entry<Object, Object> entry = map.next();
//            maps.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
//        }
//    }

    // 方式2：静态代码块加载配置信息
    static {
        Iterator<Map.Entry<Object, Object>> map = properties.properties.entrySet().iterator();
        while (map.hasNext()) {
            Map.Entry<Object, Object> entry = map.next();
            maps.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
        }
    }
}
